package com.base.work;


import android.support.v7.widget.GridLayoutManager;
import android.view.View;

import com.alibaba.android.arouter.launcher.ARouter;
import com.base.commonlib.base.CBaseMvpFragment;
import com.base.commonlib.bean.StatEntity;
import com.base.commonlib.recy.HFGridMultiTypeGapDecoration;
import com.base.commonlib.recy.HFMultiTypeRecyAdapter;
import com.base.commonlib.recy.animation.ScaleInAnimation;
import com.base.commonlib.utils.RxBus2;
import com.base.commonlib.utils.ToastUtil;
import com.base.work.adapter.HFGridMuiltType;
import com.base.work.adapter.WorkData;
import com.base.work.databinding.FragmentWorkBinding;

/**
 * Created by zw on 2019/2/12.
 */

public class WorkFragment extends CBaseMvpFragment  {

    protected FragmentWorkBinding mBinding;


    private HFMultiTypeRecyAdapter mAdapter;
    @Override
    public void init() {
        mBinding = (FragmentWorkBinding) mRootBinding;

    }

    @Override
    public void start() {
        mBinding.imgRight.setVisibility(View.GONE);
        mBinding.imgRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //ToastUtil.show("群组功能敬请期待");
                //ARouter.getInstance().build("/chat/chat_window").navigation();
                //ARouter.getInstance().build("/friend/add").navigation();
                ARouter.getInstance().build("/chat/friendandmessage").navigation();
            }
        });
        RxBus2.getInstance().post(new StatEntity(1));
        if (mAdapter == null) {
            mAdapter = new HFMultiTypeRecyAdapter();
            mAdapter.openLoadAnimation(new ScaleInAnimation());
            mBinding.recycler.setAdapter(mAdapter);
            GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 12);
            HFGridMuiltType spanSizeLookup = new HFGridMuiltType();
            spanSizeLookup.setAdapter(mAdapter);
            spanSizeLookup.setLayoutManager(gridLayoutManager);
            gridLayoutManager.setSpanSizeLookup(spanSizeLookup);
            mBinding.recycler.setLayoutManager(gridLayoutManager);
            HFGridMultiTypeGapDecoration gapDecoration = new HFGridMultiTypeGapDecoration(0);
            gapDecoration.setOffsetTopEnabled(false);
            mBinding.recycler.addItemDecoration(gapDecoration);
        }
        mAdapter.refreshDatas(WorkData.getWorkSearchFragmentDatas());
    }


    @Override
    public void onHiddenChanged(boolean hidden) {
        if (!hidden){
            RxBus2.getInstance().post(new StatEntity(1));
        }
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_work;
    }
}
